#ifndef EPUBZLIB_COMM_THREAD_HPP
#define EPUBZLIB_COMM_THREAD_HPP

SJR_NAMESPACE_BEGIN

class EpubThread final {
public:
  struct OnThreadRunnableListener {
    virtual ~OnThreadRunnableListener() = default;

    virtual void onThreadRun() = 0;
  };

  explicit EpubThread(OnThreadRunnableListener *listener = nullptr) : mListener(listener) {}

  EpubThread(EpubThread const &) = delete;
  EpubThread &operator=(EpubThread const &) = delete;

  void setOnThreadRunnableListener(OnThreadRunnableListener *listener) {
    mListener = listener;
  }

  void start() {
    std::thread([=]() {
      if (mListener != nullptr)
        (*mListener).onThreadRun();
    }).detach();
  }

private:
  OnThreadRunnableListener *mListener;
};

SJR_NAMESPACE_END

#endif//EPUBZLIB_COMM_THREAD_HPP
